home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************************/
- /* Calculate π by Leonhard Euler approximation */
- /* π ≈ √ { 6 ( 1/1 + 1/4 + 1/9 + 1/16 + 1/25 ... + 1/(n+1)**2 ...) } */
- /* */
- /* */
- /* M\Cooper */
- /* 3425 Chestnut Ridge Rd. */
- /* Grantsville, MD 21536 */
- /* ------------------------- */
- /* email: thegrendel@aol.com */
- /* 06/91 */
- /* Source code placed in the public domain */
- /**************************************************************************/
-
- #include <stdio.h>
- #include <math.h>
-
- #define MAX 5000
-
- void main()
- {
- double intermediate_result = 0,
- Pi;
- register int k;
-
-
-
-
- for( k = 0; k <= MAX; k++ )
- {
- intermediate_result += 1.0 / ( ( k + 1.0 ) * ( k + 1.0 ) );
- Pi = sqrt( 6.0 * intermediate_result );
-
- printf( "Term #%5d -------> π ≈ %f \n", k, Pi );
- }
-
- }
-
-
-
-
-